import 'package:fluent_ui/fluent_ui.dart' as flu;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:syria_sports/core/app_export.dart';
import 'package:syria_sports/core/utils/show_toast.dart';


/// Checks if the current environment is a desktop environment.
bool get isDesktop {
  if (kIsWeb) return false;
  return [
    TargetPlatform.windows,
    TargetPlatform.linux,
    TargetPlatform.macOS,
  ].contains(defaultTargetPlatform);
}
// ignore: must_be_immutable
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
  const CustomAppBar({
    Key? key,
    this.height,
    this.leadingWidth,
    this.leading,
    this.title,
    this.centerTitle,
    this.actions,
    this.bottom,
  }) : super(
          key: key,
        );

  final double? height;

  final double? leadingWidth;

  final Widget? leading;

  final Widget? title;

  final bool? centerTitle;

  final List<Widget>? actions;
  final PreferredSizeWidget? bottom;

  @override
  Widget build(BuildContext context) {
    return AppBar(
      elevation: 1,
      toolbarHeight: height,
      automaticallyImplyLeading: false,
      backgroundColor: Theme.of(context).appBarTheme.backgroundColor,
      leadingWidth: leadingWidth,
      leading: leading,
      title: title,
      titleSpacing: 0,
      centerTitle: centerTitle ?? true,
      actions: actions,
      bottom:isDesktop? bottom:null,
    );
  }

  @override
  Size get preferredSize => Size(
        mediaQueryData.size.width,
    (isDesktop && bottom != null)?(height ?? 56*2):(height ?? 56),
    //(bottom != null)?(height ?? 56*2):(height ?? 56),
      );
}



class WinAppBar extends StatelessWidget implements PreferredSizeWidget{
  const WinAppBar({
    Key? key,
    this.height,
    this.leadingWidth,
    this.leading,
    this.title,
    this.centerTitle,
    this.actions,
    this.onDeleteItems,
    this.onRefresh,
    this.onPressNew,
    this.onSelectAll,
    this.onUnSelectAll,
  }) : super(
    key: key,
  );

  final double? height;

  final double? leadingWidth;

  final Widget? leading;

  final Widget? title;

  final bool? centerTitle;

  final List<Widget>? actions;
  final Function()? onDeleteItems;
  final Function()? onRefresh;
  final Function()? onPressNew;
  final Function()? onSelectAll;
  final Function()? onUnSelectAll;

  @override
  Widget build(BuildContext context) {

    final simpleCommandBarItems = <flu.CommandBarItem>[
      flu.CommandBarBuilderItem(
        builder: (context, mode, w) => flu.Tooltip(
          message: "Create something new!",
          child: w,
        ),
        wrappedItem: flu.CommandBarButton(
          icon: const flu.Icon(flu.FluentIcons.add),
          label: const flu.Text('New'),
          onPressed: onPressNew,
        ),
      ),
      flu.CommandBarButton(
        icon: const flu.Icon(flu.FluentIcons.delete),
        label: const flu.Text('حذف'),
        onPressed: onDeleteItems,
      ),
      /*flu.CommandBarButton(
        icon: const flu.Icon(flu.FluentIcons.archive),
        label: const flu.Text('Archive'),
        onPressed: () {},
      ),*/
      flu.CommandBarButton(
        icon: const flu.Icon(flu.FluentIcons.refresh),
        label: const flu.Text('تحديث'),
        onPressed: onRefresh,
      ),
      const flu.CommandBarButton(
        icon: flu.Icon(flu.FluentIcons.cancel),
        label: flu.Text('Disabled'),
        onPressed: null,
      ),
      flu.CommandBarButton(
        icon: const flu.Icon(flu.FluentIcons.select_all),
        label: const flu.Text('تحديد الكل'),
        onPressed: onSelectAll,
      ),
      flu.CommandBarButton(
        icon: const flu.Icon(flu.FluentIcons.clear_selection),
        label: const flu.Text('إلغاء التحديد'),
        onPressed: onUnSelectAll,
      ),
    ];


    return flu.FluentTheme(
      data: flu.FluentThemeData(
        brightness: flu.Brightness.dark,
        visualDensity: flu.VisualDensity.standard,
        focusTheme: const flu.FocusThemeData(
          glowFactor: 2.0,
        ),
      ),
      child: flu.CommandBar(
        overflowBehavior: flu.CommandBarOverflowBehavior.wrap,
        compactBreakpointWidth: 350,
        primaryItems: [
          ...simpleCommandBarItems,
        ],
      ),
    );
  }
  @override
  Size get preferredSize => Size(
    mediaQueryData.size.width,
    height ?? 56,
  );
}